package neuroBot.exploit.fulltilt;

import java.awt.Color;
import java.awt.Robot;

import neuroBot.exploit.DealerFinder;

public class DealerFinderFullTilt implements DealerFinder {

	public static final int[] buttonPosXY = new int[] { 549, 192, 632, 236,
			661, 340, 522, 420, 328, 432, 270, 418, 134, 318, 155, 251, 294,
			186 };

	public Robot rob;

	public DealerFinderFullTilt() {
		try {
			rob = new Robot();
			rob.setAutoWaitForIdle(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public int getDealerPosition(int tnr) {
		int ds = getRedButtonPos(tnr);
		while (ds < 0)
			ds = getRedButtonPos(tnr);
		return ds;
	}

	protected int getRedButtonPos(int tnr) {
		for (int i = 0; i < 3; i++) {
			for (int s = 0; s < 9; s++) {
				Color col = rob.getPixelColor(buttonPosXY[s * 2],
						buttonPosXY[s * 2 + 1]);
				if (col.equals(Color.RED))
					return s;
			}
			System.err.println(this.getClass() + " Error finding button!!!");
		}
		return -1;
	}

}
